package hu.monitor.agent.remoting;

import hu.monitor.remoting.InvocationContext;
import hu.monitor.remoting.Invoker;
import hu.monitor.remoting.InvokerInterceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

public class SpringBeanInvokerInterceptor implements InvokerInterceptor {
	@Autowired
	private ApplicationContext context;

	@Override
	public Object intercept(final InvocationContext invocationContext) throws Throwable {
		final Object bean = this.context.getBean(invocationContext.getRemoteInterface());
		final Invoker invoker = new Invoker(invocationContext, bean);
		return invoker.invoke();
	}

}
